/**══════════════════════════════════╗
*作    者：songbaobao                                                 ║
*职    业：我以我血荐轩辕                                              ║                                              
*CSND地址：https://blog.csdn.net/weixin_43949535                       ║
**GitHub ：https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*创建时间：                                                           
*功能描述：                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*结束时间:                                                           
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              西南\./联大               \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/
#include <iostream>
#include <vector>
#include <string.h>
#include <unordered_map>
#include <ctype.h>
#include <queue>
#include <list>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <stdbool.h>
using namespace std;


int main()
{
#if A
	int mytree[10001] = { 0 }, L, M;

	while (scanf("%d%d", &L, &M), L || M)
	{
		int result = 0;
		for (int i = 0; i <= L; ++i)
		{
			mytree[i] = 1;
		}

		while (M--)
		{
			int begin, end;
			scanf("%d%d", &begin, &end);
			for (int i = begin; i <= end; ++i)
				mytree[i] = 0;
		}	
		
		for (int i = 0; i <= L; ++i)
		{
			if (mytree[i] == 1)
				result++;
		}
		printf("%d\n", result);
	}
#endif	

#if B
	char Astr[20] = { 0 };
	char Bstr[20] = { 0 };

	while (EOF != scanf("%s %s", Astr, Bstr))
	{
		char* pa = Astr, * pb = Bstr;
		int Aint = 0, Bint = 0;
		int flag = -1;
		while (*pa != '\0')
		{
			if (*pa != ',' && *pa != '-')
			{
				Aint *= 10;
				Aint += (*pa - '0');
			}
			pa++;
		}
		while (*pb != '\0')
		{
			if (*pb != ',' && *pb != '-')
			{
				Bint *= 10;
				Bint += (*pb - '0');
			}
			pb++;
		}
		if (*Astr == '-')
			Aint *= flag;
		if (*Bstr == '-')
			Bint *= flag;

		memset(Astr, 0, 20);
		memset(Bstr, 0, 20);
		printf("%d\n", Aint + Bint);
	}
#endif

#if C
	int Astr[11] = { 0 };
	int Bstr[11] = { 0 };

	int data1 = 0, data2 = 0;
	while (EOF != scanf("%d%d", &data1, &data2))
	{
		int result = 0, lenA = 0, lenB = 0;
		for (int i = 0; data1 != 0; ++i)
		{
			Astr[i] = (data1 % 10);
			data1 /= 10;
			lenA++;
		}
		for (int i = 0; data2 != 0; ++i)
		{
			Bstr[i] = (data2 % 10);
			data2 /= 10;
			lenB++;
		}
		for (int i = 0; i < lenA; ++i)
		{
			for (int j = 0; j < lenB; ++j)
			{
				result += (Astr[i] * Bstr[j]);
			}
		}			

		memset(Astr, 0, 11 * sizeof(int));
		memset(Bstr, 0, 11 * sizeof(int));

		printf("%d\n", result);
	}
#endif

#if D
	int N, count1 = 0, count2 = 0, data;
	while (EOF != scanf("%d", &N))
	{
		while (N--)
		{
			scanf("%d", &data);
			if (data % 2 == 0)
				count2++;
			else
				count1++;
		}
		if (count2 > count1)
		{
			printf("NO\n");
		}
		else
			printf("YES\n");
	}
#endif	
	
#if E
	int myarray[100001] = { 0 };
	int distenseToFisrst[100001] = { 0 };
	int N, M;
	while (EOF != scanf("%d", &N))
	{
		int total = 0, left, right;
		for (int i = 1; i <= N; ++i)
		{
			scanf("%d", myarray + i);

			/* 意思就是：第一个距离就是点2到点1的距离，也就是distenseToFisrst[1] */
			distenseToFisrst[i] = distenseToFisrst[i - 1] + myarray[i];
			total += myarray[i];
		}

		scanf("%d", &M);
		while (M--)
		{
			int result1 = 0, temp;
			scanf("%d%d", &left, &right);
			if (left > right)
			{
				temp = right;
				right = left;
				left = temp;
			}
			/* 尽量避免双层循环,会时间超时 */
			/*
			for (int i = left; i < right; ++i)
			{
				result1 += myarray[i];
			} */

			result1 = distenseToFisrst[right - 1] - distenseToFisrst[left - 1];
			if (result1 < (total - result1))
			{
				printf("%d\n", result1);
			}
			else
				printf("%d\n", total - result1);
		}
		
	}
#endif

#if F
	int Aint, Bint, Cint, N = 0;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> Aint >> Bint >> Cint;
		if ((Aint / 2.0 + Bint / 2.0) > (Cint / 2.0))
		{
			cout << "Case #" << i + 1 << ": true" << endl;
		}
		else
			cout << "Case #" << i + 1 << ": false" << endl;
	}
#endif

#if G
	int N, A1 = 0, A2 = 0, A3 = 0, A4 = 0, A5 = 0, data;
	while (EOF != scanf("%d", &N))
	{
		int flag = 1, count = 0;
		bool existflag = false;
		while (N--)
		{
			scanf("%d", &data);

			switch (data % 5)
			{
			case 0:
				if (data % 2 == 0)
				{
					A1 += data;
				}
				break;
			case 1:
				existflag = true;
				A2 += (data * flag);
				flag *= -1;
				break;
			case 2:
				A3++;
				break;
			case 3:
				A4 += data;
				count++;
				break;
			case 4:
				if (data > A5)
					A5 = data;
			}
		}
		if (A1 == 0)
			printf("N ");
		else
			printf("%d ", A1);

		if (A2 == 0 && !existflag)
			printf("N ");
		else
			printf("%d ", A2);

		if (A3 == 0)
			printf("N ");
		else
			printf("%d ", A3);

		if (A4 == 0)
			printf("N ");
		else
			printf("%.1lf ", (double)A4 / count);

		if (A5 == 0)
			printf("N ");
		else
			printf("%d\n", A5);
		A1 = 0, A2 = 0, A3 = 0, A4 = 0, A5 = 0;
	}
#endif

#if H
	int Aint, Bint, Da, Db, Pa = 0, Pb = 0;
	while (EOF != scanf("%d%d%d%d", &Aint, &Da, &Bint ,&Db))
	{
		while (Aint != 0)
		{
			if (Aint % 10 == Da)
			{
				Pa *= 10;
				Pa += Da;
			}
			Aint /= 10;
		}
		while (Bint != 0)
		{
			if (Bint % 10 == Db)
			{
				Pb *= 10;
				Pb += Db;
			}
			Bint /= 10;
		}
		printf("%d\n", Pa + Pb);
		Pa = Pb = 0;
	}
#endif

	
	int N, successOf1 = 0, failureOf1 = 0, average = 0, total = 0;
	char first, second;

	/* C[0]-'B' C[1]-'C' C[2]-'J' */
	char C[3] = { 'B','C','J' };
	int succCount[3] = { 0 }, failureCount[3] = { 0 }, maxCount1 = 0, maxCount2 = 0;
	int maxIndex1 = 0, maxIndex2 = 0;

	cin >> N;
	total = N;
	while (N--)
	{
		cin >> first >> second;
		if (first == second)
		{
			average++;
			continue;
		}

		if (first == 'C')
		{
			if (second == 'J')
			{
				successOf1++;
				succCount[1]++;
			}
			else
				failureCount[0]++;
		}
		
		if (first == 'J')
		{
			if (second == 'B')
			{
				successOf1++;
				succCount[2]++;
			}
			else
				failureCount[1]++;
		}
		
		if (first == 'B')
		{
			if (second == 'C')
			{
				successOf1++;
				succCount[0]++;
			}
			else
				failureCount[2]++;
		}
	}
	failureOf1 = total - successOf1 - average;


	printf("%d %d %d\n", successOf1, average, failureOf1);
	printf("%d %d %d\n", failureOf1, average, successOf1);

	for (int i = 0; i < 3; ++i)
	{
		if (succCount[i] > maxCount1)
		{
			maxCount1 = succCount[i];
			maxIndex1 = i;
		}	

		if (failureCount[i] > maxCount2)
		{
			maxCount2 = failureCount[i];
			maxIndex2 = i;
		}
	}
	printf("%c %c\n", C[maxIndex1], C[maxIndex2]);
	return 0;
}
/**
*备用注释：
*
*
*
*/